package com.wsx.java.boddy.agent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author wangshuaixin
 * @Title: com.wsx.java.boddy.agent.Monitor
 * @Description: TODO
 * @date 2019/01/23
 */
public class Monitor {

    private Monitor() {}

    private static final Monitor instance = new Monitor();

    private static final ScheduledExecutorService SERVICE = Executors.newScheduledThreadPool(1);


    public static Monitor getInstance() {
        return instance;
    }

    private static volatile boolean start = false;

    public void start() {
        if (!start) {
            SERVICE.scheduleAtFixedRate(new Runnable() {
                @Override
                public void run() {
                    Metric.printMemoryInfo();
                    Metric.printGCInfo();
                }
            }, 0, 5000, TimeUnit.MILLISECONDS);
            start = true;
        }
    }
}
